package com.naicheng.ivote.engin;

import com.naicheng.ivote.R;
import com.naicheng.ivote.utils.AppManager;
import com.naicheng.ivote.utils.LogUtils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;


public abstract class BaseAnimActivity extends Activity implements OnClickListener {

	protected ProgressDialog mpDialog;
	protected boolean is_alert_request_dialog = true;
	public boolean activityStatus = false;
	protected GestureDetector mGestureDetector;// 定义手势识别器
	protected static final String TAG = "BaseAnimActivity";
	

	// protected boolean isclosed = true;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		mGestureDetector = new GestureDetector(
				new GestureDetector.SimpleOnGestureListener() {

					@Override
					public boolean onFling(MotionEvent e1, MotionEvent e2,
							float velocityX, float velocityY) {

						if (Math.abs(e1.getRawY() - e2.getRawY()) > 300) {
							LogUtils.logi(TAG, "垂直方向移动过大,动作不合法");
							return true;
						}

						if (Math.abs(velocityX) < 100) {
							LogUtils.logi(TAG, "滑动的太慢,动作不合法");
							return true;
						}

						if ((e2.getRawX() - e1.getRawX()) > 100) {
							// 显示上一个
							// showPre();
							pre(null);
							return true;
						}
						if ((e1.getRawX() - e2.getRawX()) > 100) {
							// 显示下一个
							// showNext();
							next(null);
							return true;
						}
						return super.onFling(e1, e2, velocityX, velocityY);
					}

				});

		setConentView();
		init();
		setOnClickListener();
		processLogic();

		AppManager.getAppManager().addActivity(this);
		// setActivityStatus(false);
	}

	
	
	@Override
	protected void onResume() {
		super.onResume();
		
	}



	@Override
	protected void onStop() {
		super.onStop();
		// setActivityStatus(true);
		// MicroFinaceApp.isStatus = true;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		// closeDialog();
		// Constants.RELOGIN_TIMES = 0;
		AppManager.getAppManager().finishActivity(this);
	}

	/*
	 * public boolean isActivityStatus() { return activityStatus; }
	 * 
	 * public void setActivityStatus(boolean activityStatus) {
	 * this.activityStatus = activityStatus; }
	 */

	@Override
	protected void onRestart() {
		super.onRestart();
		// setActivityStatus(false);
	}

	/**
	 * 加载布局xml文件
	 */
	protected void setConentView() {

	}

	/**
	 * 初始化view控件
	 */
	protected void init() {

	}

	/**
	 * 逻辑数据处理
	 */
	protected void processLogic() {

	}

	/**
	 * 弹出Toast
	 * 
	 * @param content
	 */
	protected void alertToast(String content) {
		Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT)
				.show();
	}

	/**
	 * 设置监听事件
	 */
	protected void setOnClickListener() {

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	// 当手指在屏幕上触摸的时候调用的方法.
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// 3.让手势识别器生效
		mGestureDetector.onTouchEvent(event);
		return super.onTouchEvent(event);
	}

	protected abstract void showNext();

	protected abstract void showPre();

	public void next(View view) {
		showNext();
		overridePendingTransition(R.anim.tran_in_next, R.anim.tran_out_next);
		//overridePendingTransition(R.anim.alpah_in, R.anim.alpah_out);
	}

	public void pre(View view) {
		showPre();
		overridePendingTransition(R.anim.tran_in_pre, R.anim.tran_out_pre);
		//overridePendingTransition(R.anim.alpah_in, R.anim.alpah_out);
	}

}
